package org.chen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.chen.model.CommentRule;

@Mapper
public interface CommentRuleMapper extends BaseMapper<CommentRule> {
    @Select("SELECT * FROM comment_rule WHERE url_pattern = #{urlPattern} ORDER BY success_rate DESC LIMIT 1")
    CommentRule findByUrlPattern(@Param("urlPattern") String urlPattern);

    @Update("""
        UPDATE comment_rule 
        SET use_count = use_count + 1,
            success_rate = #{newSuccessRate},
            last_used_time = NOW()
        WHERE id = #{id}
    """)
    void updateRuleStats(@Param("id") Long id, @Param("newSuccessRate") Double newSuccessRate);
}
